package v1

import (
	"gomicro-sharemod/gateway-api/controllers"
	"strconv"

	"github.com/gin-gonic/gin"
)

/*
 +----------------------------------------------------------------------
 + Title        : AccountController
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2019-08-08
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 用户控制器
 +----------------------------------------------------------------------
*/
type AccountController struct {
	controllers.BaseController
}

/**
 * 用户名登录
 *
 * @param string username --------------------------------必传,用户名
 * @param string password --------------------------------必传,密码
 * @param string captcha ---------------------------------必传,验证码
 * @param string captcha_id ------------------------------必传,验证码ID
 * @return Json
 * @author huwl
 */
func (control AccountController) Login(ctx *gin.Context) {
	username := ctx.DefaultPostForm("username", "")
	password := ctx.DefaultPostForm("password", "")
	// captcha := ctx.DefaultPostForm("captcha", "")
	// captchaId := ctx.DefaultPostForm("captcha_id", "")

	if username == "" {
		control.BaseError(ctx, control.WithMessage("请输入用户名"))
		return
	}
	if password == "" {
		control.BaseError(ctx, control.WithMessage("请输入密码"))
		return
	}

	control.BaseSuccess(ctx, control.WithMessage("账户登录"))
}

/**
 * 详情
 *
 * @param int id -----------------------------------------必传,ID
 * @return Json
 * @author huwl
 */
func (control AccountController) Detail(ctx *gin.Context) {
	id, _ := strconv.ParseInt(ctx.DefaultQuery("id", "0"), 10, 64)

	if id <= 0 {
		control.BaseError(ctx, control.WithMessage("账户ID错误"))
		return
	}

	control.BaseSuccess(ctx, control.WithMessage("账户详情"))
}

/**
 * 获取当前登录账户详情
 *
 * @return Json
 * @author huwl
 */
func (control AccountController) GetCurrentLoginAccountDetail(ctx *gin.Context) {
	// id, _ := ctx.Get("account_id")
	// accountId, _ := strconv.ParseInt(id.(string), 10, 64)

	control.BaseSuccess(ctx, control.WithMessage("当前登录账户详情"))
}
